﻿using Ah.Testudin.Engine.Events;

using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.Actors.Components.Collision
{
    public class ExplosionCollisionHandlerComponent : ActorComponentBase, ICollisionHandlerComponent
    {
        #region Private Member Variables

        private readonly float _radius;

        private readonly float _force;

        private readonly int _damage;

        #endregion

        #region Constructors

        public ExplosionCollisionHandlerComponent(
            Actor owner,
            IEventManager eventManager,
            float radius,
            float force,
            int damage)
            : base(owner, eventManager)
        {
            _radius = radius;

            _force = force;

            _damage = damage;
        }

        #endregion

        #region ActorComponentBase

        public override void Update(GameTime gameTime)
        {            
        }

        #endregion

        #region ICollisionHandlerComponent

        public void HandleCollision()
        {
            _eventManager.QueueEvent(
                new ActorDestroyedEvent(
                    this.Owner.Id));

            _eventManager.QueueEvent(
                new ExplosionEvent(
                    this.Owner,
                    _radius,
                    _force,
                    _damage));

            this.Owner.SetComponent<ICollisionHandlerComponent>(null);
        }

        #endregion
    }
}
